<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">
    <el-form
      ref="detailFormRef"
      :model="formData"
      v-loading="formLoading"
      label-width="100px"
      :inline-message="true"
    >
      <el-table :data="formData" >
        <el-table-column label="序号" type="index" width="60" />
        <el-table-column label="长客订单号" align="center" prop="displayPoNumber"  width="150px" />
<!--        <el-table-column label="订单总金额" align="center" prop="sumAmount"  width="150px" />-->
        <el-table-column label="采购员" align="center" prop="agentName" />
        <el-table-column label="物料号" align="center" prop="itemCode" width="150px" />
        <el-table-column label="物料名称" align="center" prop="itemDescription" width="150px"  />
        <el-table-column label="单位" align="center" prop="unitMeasLookupCode" />
        <el-table-column label="单价" align="center" prop="unitPrice" />
        <el-table-column label="每" align="center" prop="eachNumber" />
        <el-table-column label="项目代码" align="center" prop="projectCode" width="150px" />
        <el-table-column label="项目名称" align="center" prop="projectName" width="150px"/>
        <el-table-column label="状态" align="center" prop="statusDesc" />

      </el-table>
    </el-form>

    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import {PurOrderApi} from "@/api/ck/purorder";

/** 采购订单关联 表单 */
defineOptions({ name: 'OrderMappingForm' })

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  id: undefined,
  displayPoNumber: undefined,
  sumAmount: undefined,
  agentName: undefined,
  itemCode: undefined,
  itemDescription: undefined,
  quantity: undefined,
  unitMeasLookupCode: undefined,
  unitPrice: undefined,
  eachNumber: undefined,
  projectCode: undefined,
  projectName: undefined,
  statusDesc: undefined,
  lineNum: undefined,
})
const detailFormRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type: string, id?: number) => {
  dialogVisible.value = true
  dialogTitle.value = "采购订单明细"
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    // 1. 重置表单
    formData.value = []
    try {
      formData.value = await PurOrderApi.getPurOrderListByOrderNo(id)
      console.log("===")
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗



</script>
